<template>
  <view class="container">
    <view class="page-items">
      <!-- 搜索框 -->
      <view class="diy-search">
        <view class="inner square">
          <view class="search-input" style="text-align: left">
            <text class="search-icon iconfont icon-search"></text>
            <text> 请输入关键字进行搜索</text>
          </view>
        </view>
      </view>
      <!-- 图片轮播 -->
      <view class="diy-banner" :style="{ height: `166px` }">
        <swiper class="swiper-box" :circular="true">
          <swiper-item v-for="item in pagesData[2].data" :key="item.id">
            <image mode="widthFix" class="slide-image" :src="item.imgUrl" />
          </swiper-item>
        </swiper>
        <!-- 指示点 -->
        <view class="indicator-dots">
          <view class="dots-item"></view>
        </view>
      </view>
      <!-- 店铺公告 -->
      <view class="diy-notice">
        <u-notice-bar
          padding="10rpx 24rpx"
          volume-icon
          autoplay
          bg-color="#fffbe8"
          color="#de8c17"
          :list="[pagesData[3].params.text]"
        ></u-notice-bar>
      </view>
      <!-- 导航组 -->
      <view class="diy-navBar">
        <view class="data-list avg-sm-4">
          <view
            class="item-nav"
            v-for="item in pagesData[4].data"
            :key="item.id"
          >
            <view class="nav-to">
              <view class="item-image">
                <image class="image" mode="widthFix" :src="item.imgUrl">
                </image>
              </view>
              <view class="item-text oneline-hide">{{ item.text }}</view>
            </view>
          </view>
        </view>
      </view>
      <!-- 商品组 -->
      <view class="diy-goods">
        <view class="goods-list display__list column__2">
          <scroll-view scroll-x style="height: 500rpx">
            <view style="display: flex; width: 300%">
              <view
                class="goods-item"
                v-for="item in pagesData[5].data"
                :key="item.goods_id"
                @click="goDetail(item.goods_id)"
              >
                <view class="goods-image">
                  <image class="image" mode="widthFix" :src="item.goods_image">
                  </image>
                </view>
                <view class="detail">
                  <!-- 商品标题 -->
                  <view class="goods-name">
                    <text class="twoline-hide">{{ item.goods_name }}</text>
                  </view>
                  <!-- 商品价格 -->
                  <view class="detail-price oneline-hide">
                    <text class="goods-price f-30 col-m"
                      >￥{{ item.goods_price_min }}</text
                    >
                    <text class="line-price col-9 f-24"
                      >￥{{ item.goods_price_max }}</text
                    >
                  </view>
                </view>
              </view>
            </view>
          </scroll-view>
        </view>
      </view>
      <!-- 视频组 -->
      <view class="diy-video">
        <video
          class="video"
          :src="pagesData[8].params.videoUrl"
          :poster="pagesData[8].params.poster"
          autoplay
          controls
        ></video>
      </view>
      <!-- 文章组 -->
      <view class="diy-article">
        <view
          class="article-item show-type__10"
          v-for="item in pagesData[9].data"
          :key="item.id"
        >
          <view class="article-item__left flex-box">
            <view class="article-item__title">
              <text class="twoline-hide">{{ item.title }}</text>
            </view>
            <view class="article-item__footer m-top10">
              <text class="article-views f-24 col-8"
                >{{ item.actual_views }}次浏览</text
              >
            </view>
          </view>
          <view class="article-item__image">
            <image class="image" mode="widthFix" :src="item.image_url"></image>
          </view>
        </view>
      </view>
      <!-- 在线客服 -->
      <view class="diy-service" :style="{ right: '20px', bottom: '100px' }">
        <!-- 拨打电话 -->
        <block>
          <view class="service-icon">
            <image
              class="image"
              src="http://124.223.14.236:8889/assets/store/img/diy/service.png"
            ></image>
          </view>
        </block>
        <!-- 在线聊天 -->
        <!-- <block >
			    <button open-type="contact" class="btn-normal">
			      <view class="service-icon">
			        <image class="image" src=""></image>
			      </view>
			    </button>
			  </block> -->
      </view>
    </view>
  </view>
</template>

<script>
import { detail } from '../../api/page'
export default {
  components: {},
  data () {
    return {
      pagesData: []
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.getIndexData()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {},

  methods: {
    async getIndexData () {
      const { data } = await detail()
      this.pagesData = data.pageData.items
      console.log(`output->res`, data)
    },
    goDetail (id) {
      uni.navigateTo({ url: `/pages/goods/detail?id=${id}` })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  background: #fff;
}

.diy-search {
  background: #f1f1f2;
  padding: 20rpx 20rpx;
  font-size: 26rpx;
}

.inner {
  height: 60rpx;
  background: #fff;
  overflow: hidden;

  &.radius {
    border-radius: 10rpx;
  }

  &.round {
    border-radius: 60rpx;
  }
}

.search-input {
  height: 60rpx;
  line-height: 60rpx;
  color: #999;
  padding: 0 20rpx;

  .search-icon {
    margin-right: 8rpx;
  }
}

.diy-banner {
  position: relative;

  // swiper组件
  .swiper-box {
    height: 100%;

    .slide-image {
      width: 100%;
      height: 100%;
      margin: 0 auto;
      display: block;
    }
  }

  /* 指示点 */
  .indicator-dots {
    width: 100%;
    height: 28rpx;
    padding: 0 20rpx;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 20rpx;
    opacity: 0.8;
    display: flex;
    justify-content: center;

    .dots-item {
      width: 16rpx;
      height: 16rpx;
      margin-right: 8rpx;
      background-color: #fff;

      &:last-child {
        margin-right: 0;
      }

      &.active {
        background-color: #313131 !important;
      }
    }

    // 圆形
    &.round .dots-item {
      width: 16rpx;
      height: 16rpx;
      border-radius: 20rpx;
    }

    // 正方形
    &.square .dots-item {
      width: 16rpx;
      height: 16rpx;
    }

    // 长方形
    &.rectangle .dots-item {
      width: 22rpx;
      height: 14rpx;
    }
  }
}

.diy-navBar .data-list::after {
  clear: both;
  content: ' ';
  display: table;
}

.item-nav {
  float: left;
  margin: 10px 0;
  text-align: center;

  .item-text {
    font-size: 26rpx;
  }

  .item-image {
    margin-bottom: 4px;
    font-size: 0;
  }

  .item-image .image {
    width: 88rpx;
    height: 88rpx;
  }
}

/* 分列布局 */

.diy-navBar .avg-sm-3 > .item-nav {
  width: 33.33333333%;
}

.diy-navBar .avg-sm-4 > .item-nav {
  width: 25%;
}

.diy-navBar .avg-sm-5 > .item-nav {
  width: 20%;
}

.diy-goods {
  .goods-list {
    padding: 4rpx;
    box-sizing: border-box;

    .goods-item {
      box-sizing: border-box;
      padding: 6rpx;
      .goods-image {
        position: relative;
        width: 100%;
        height: 0;
        padding-bottom: 100%;
        overflow: hidden;
        background: #fff;

        &:after {
          content: '';
          display: block;
          margin-top: 100%;
        }

        .image {
          position: absolute;
          width: 100%;
          height: 100%;
          top: 0;
          left: 0;
          -o-object-fit: cover;
          object-fit: cover;
        }
      }

      .detail {
        padding: 8rpx;
        background: #fff;

        .goods-name {
          min-height: 68rpx;
          line-height: 1.3;
          white-space: normal;
          color: #484848;
          font-size: 26rpx;
        }

        .detail-price {
          .goods-price {
            margin-right: 8rpx;
          }

          .line-price {
            text-decoration: line-through;
          }
        }
      }
    }

    &.display__slide {
      white-space: nowrap;
      font-size: 0;

      .goods-item {
        display: inline-block;
      }
    }

    &.display__list {
      .goods-item {
        float: left;
      }
    }

    &.column__2 {
      .goods-item {
        width: 50%;
      }
    }

    &.column__3 {
      .goods-item {
        width: 33.33333%;
      }
    }

    &.column__1 {
      .goods-item {
        width: 100%;
        height: 280rpx;
        margin-bottom: 12rpx;
        padding: 20rpx;
        box-sizing: border-box;
        background: #fff;
        line-height: 1.6;

        &:last-child {
          margin-bottom: 0;
        }
      }

      .goods-item_left {
        display: flex;
        width: 40%;
        background: #fff;
        align-items: center;

        .image {
          display: block;
          width: 240rpx;
          height: 240rpx;
        }
      }

      .goods-item_right {
        position: relative;
        width: 60%;

        .goods-name {
          margin-top: 20rpx;
          min-height: 68rpx;
          line-height: 1.3;
          white-space: normal;
          color: #484848;
          font-size: 26rpx;
        }
      }

      .goods-item_desc {
        margin-top: 8rpx;
      }

      .desc-selling_point {
        width: 400rpx;
        font-size: 24rpx;
        color: #e49a3d;
      }

      .desc-goods_sales {
        color: #999;
        font-size: 24rpx;
      }

      .desc_footer {
        font-size: 24rpx;

        .price_x {
          margin-right: 16rpx;
          color: #f03c3c;
          font-size: 30rpx;
        }

        .price_y {
          text-decoration: line-through;
        }
      }
    }
  }
}

.diy-video .video {
  width: 100%;
  display: block;
}

.diy-article {
  background: #f7f7f7;

  .article-item {
    margin-bottom: 20rpx;
    padding: 30rpx;
    background: #fff;

    &:last-child {
      margin-bottom: 0;
    }

    .article-item__title {
      max-height: 74rpx;
      font-size: 28rpx;
      line-height: 38rpx;
      color: #333;
    }

    .article-item__image .image {
      display: block;
    }
  }
}

/* 小图模式 */

.show-type__10 {
  display: flex;

  .article-item__left {
    padding-right: 20rpx;
  }

  .article-item__title {
    // min-height: 72rpx;
  }

  .article-item__image .image {
    width: 240rpx;
  }
}

/* 大图模式 */

.show-type__20 .article-item__image .image {
  width: 100%;
}

.diy-article {
  background: #f7f7f7;

  .article-item {
    margin-bottom: 20rpx;
    padding: 30rpx;
    background: #fff;

    &:last-child {
      margin-bottom: 0;
    }

    .article-item__title {
      max-height: 74rpx;
      font-size: 28rpx;
      line-height: 38rpx;
      color: #333;
    }

    .article-item__image .image {
      display: block;
    }
  }
}

/* 小图模式 */

.show-type__10 {
  display: flex;

  .article-item__left {
    padding-right: 20rpx;
  }

  .article-item__title {
    // min-height: 72rpx;
  }

  .article-item__image .image {
    width: 240rpx;
  }
}

/* 大图模式 */

.show-type__20 .article-item__image .image {
  width: 100%;
}
.diy-service {
  position: fixed;
  z-index: 999;
  right: calc(var(--window-right) + var(--right));
  bottom: calc(
    constant(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom)
  );
  bottom: calc(
    env(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom)
  );

  .service-icon {
    padding: 10rpx;

    .image {
      display: block;
      width: 90rpx;
      height: 90rpx;
      border-radius: 50%;
      box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
    }
  }
}
</style>
